package com.mage.servlet;

import com.mage.bean.User;
import com.mage.dao.UserDao;
import com.mage.dao.impl.UserDaoImpl;

import javax.servlet.HttpConstraintElement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/EditUserInfoServlet")
public class EditUserInfoServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public EditUserInfoServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            //1. 接收id
            int userid = Integer.parseInt(request.getParameter("userid"));

            //2. 查询数据
            UserDao service = new UserDaoImpl();
            User user = service.findUserById(userid);
            System.out.println(user.toString());
            //3. 显示数据
            //存数据
            request.setAttribute("user", user);
            //跳转
            request.getRequestDispatcher("Super/User_UpdateUser.jsp").forward(request, response);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
